The Scripting app allows you to create iOS home screen widgets using TypeScript and a React-like TSX syntax. Widgets are defined in a widget.tsx
file using SwiftUI components.
widget.tsx
Filewidget.tsx
.scripting
package.Calling Widget.present()
renders the component as a widget on your home screen.
You can use the following properties from the Widget
API to adapt your layout and content:
Property | Description |
---|---|
Widget.displaySize |
The actual pixel size of the widget at runtime. |
Widget.family |
The widget family: 'small' , 'medium' , or 'large' . |
Widget.parameter |
A user-defined parameter configured in the widget's home screen settings. |
Use these properties to tailor layout, content, or conditional views based on widget size or user preference.
Once configured, your widget.tsx
component will be rendered directly on the home screen.
Use built-in components inspired by SwiftUI (such as VStack
, HStack
, Text
, Image
, etc.) to build your widget layout. You may structure your code by splitting logic and views into separate files and importing them as modules.
While you can technically use React-style hooks such as useState
, useEffect
, etc., they will not take effect in widgets, because widgets are rendered once with no retained state or interaction cycle. Avoid relying on any dynamic state logic.
iOS imposes a memory limit for widgets — approximately 30MB. To stay within budget:
Rendering failures or blank widgets often indicate memory issues.
After calling Widget.present(...)
, the current execution context will be immediately destroyed. You must:
Widget.present
, as it won’t execute.Although widgets are mostly static, basic interaction is supported via AppIntents:
<Button>
or <Toggle>
to trigger AppIntent
actions.Not all SwiftUI views are supported in widgets. Certain layout containers and effects are not available. Refer to Apple’s documentation on Supported SwiftUI Views in WidgetKit to ensure compatibility.
The widget preview inside the Scripting app is only an approximation. Actual rendering on the iOS home screen may differ slightly in:
To validate your layout, always test the widget directly on the home screen.
Widget.reloadAll()
within a script (in the code of your AppIntents or index.tsx
) to refresh all widgets immediately.This enables rapid iteration when adjusting layout or logic.
Widget.preview
During development, you can use Widget.preview()
to programmatically preview a widget from index.tsx
with specific parameters and layout configuration, without having to go back to the home screen.
Widget.preview(options)
This method renders a preview of your widget in-app, simulating different parameter configurations and sizes. It is intended only for development use and must be called from the index.tsx
context (not from widget.tsx
or intent.tsx
).
Property | Type | Description |
---|---|---|
family |
'systemSmall' | 'systemMedium' | 'systemLarge' |
Optional. Specifies the widget size to preview. Defaults to 'systemSmall' . |
parameters.options |
Record<string, string> |
A record mapping parameter names to JSON-encoded strings representing input values. |
parameters.default |
string |
The name of the default parameter option to use during preview. |
This allows you to test how your widget responds to different inputs (e.g., colors, content types, or configuration states) without going through the home screen widget settings.
index.tsx
, such as in manual test scripts or development tools.